package com.xy.biz.base.domain.converter;

import java.util.Collection;
import java.util.List;

import com.xy.biz.base.domain.dto.GoodsDTO;
import com.xy.tool.util.BeanUtilsEx;
import com.xy.biz.base.domain.bo.GoodsBO;
import com.xy.biz.base.domain.po.GoodsPO;
import com.xy.biz.base.domain.query.GoodsQuery;
import com.xy.biz.base.domain.resp.GetGoodsResponse;
import com.xy.biz.base.domain.req.SaveGoodsRequest;
import com.xy.biz.base.domain.req.ListGoodsRequest;

/**
 *
 *
 * @author zgy
 * @date 2021-9-22
 */
public class GoodsConverter {

    public static GoodsPO toPO(GoodsBO source) {
        return BeanUtilsEx.copyProperties(source, () -> new GoodsPO(), true);
    }

    public static List<GoodsPO> toPO(Collection<GoodsBO> source) {
        return BeanUtilsEx.copyPropertiesForNewList(source, () -> new GoodsPO(), true);
    }

    public static GoodsBO fromPO(GoodsPO source) {
        return BeanUtilsEx.copyProperties(source, () -> new GoodsBO());
    }

    public static List<GoodsBO> fromPO(Collection<GoodsPO> source) {
        return BeanUtilsEx.copyPropertiesForNewList(source, () -> new GoodsBO());
    }

    public static GoodsBO toBO(SaveGoodsRequest source) {
        return BeanUtilsEx.copyProperties(source, () -> new GoodsBO(), true);
    }

    public static List<GoodsBO> toBO(Collection<SaveGoodsRequest> source) {
        return BeanUtilsEx.copyPropertiesForNewList(source, () -> new GoodsBO(), true);
    }

    public static GetGoodsResponse toResponse(GoodsBO source) {
        return BeanUtilsEx.copyProperties(source, () -> new GetGoodsResponse());
    }

    public static List<GetGoodsResponse> toResponse(Collection<GoodsBO> source) {
        return BeanUtilsEx.copyPropertiesForNewList(source, () -> new GetGoodsResponse());
    }

    public static List<GoodsDTO> toDTO(Collection<GoodsBO> source) {
        return BeanUtilsEx.copyPropertiesForNewList(source, GoodsDTO::new);
    }

    public static GoodsQuery toQuery(ListGoodsRequest source) {
        if (null == source) {
            return null;
        }
        GoodsQuery target = new GoodsQuery(source.getPageIndex(), source.getPageSize());
        BeanUtilsEx.copyProperties(source, target);
        return target;
    }

}
